package com.ruoyi.personnelMatters.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.personnelMatters.domain.*;
import com.ruoyi.personnelMatters.mapper.PersonScheduledMapper;
import com.ruoyi.personnelMatters.service.IPersonScheduledService;
import com.ruoyi.system.service.ISysCommonService;
import com.ruoyi.system.service.ISysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 定时任务表新增实现类
 */
@Service
public class PersonScheduledService implements IPersonScheduledService {

    @Autowired
    private PersonScheduledMapper PersonScheduledMapper;

    @Autowired
    private ISysCommonService sysCommonService;

    @Autowired
    private ISysPostService sysPostService;

    @Override
    public int insertDeptChangeScanInfo(DeptChangeScanInfo deptChangeScanInfo) {
        return PersonScheduledMapper.insertDeptChangeScanInfo(deptChangeScanInfo);
    }

    @Override
    public int insertPositionChangeScanInfo(PositionChangeScanInfo positionChangeScanInfo) {
        return PersonScheduledMapper.insertPositionChangeScanInfo(positionChangeScanInfo);
    }

    @Override
    public int insertSalaryChangeScanInfo(SalaryChangeScanInfo salaryChangeScanInfo) {
        return PersonScheduledMapper.insertSalaryChangeScanInfo(salaryChangeScanInfo);
    }

    @Override
    public int insertPostChangeScanInfo(PostChangeScanInfo postChangeScanInfo) {
        postChangeScanInfo.setOldPostName(sysPostService.selectPostById(postChangeScanInfo.getOldPostId()).getPostName());
        postChangeScanInfo.setNewPostName(sysPostService.selectPostById(postChangeScanInfo.getNewPostId()).getPostName());
        return PersonScheduledMapper.insertPostChangeScanInfo(postChangeScanInfo);
    }

    @Override
    public int insertEmployeeStatusChangeScanInfo(EmployeeStatusScanInfo employeeStatusScanInfo) {
        return PersonScheduledMapper.insertEmployeeStatusChangeScanInfo(employeeStatusScanInfo);
    }

    @Override
    public List<PositionChangeScanInfo> selectPositionChangeScanInfoList(PositionChangeScanInfo positionChangeScanInfo) {
        return PersonScheduledMapper.selectPositionChangeScanInfoList(positionChangeScanInfo);
    }

    @Override
    public List<PostChangeScanInfo> selectPostChangeScanInfoList(PostChangeScanInfo postChangeScanInfo) {
        return PersonScheduledMapper.selectPostChangeScanInfoList(postChangeScanInfo);
    }

    @Override
    public List<DeptChangeScanInfo> selectDeptChangeScanInfoList(DeptChangeScanInfo deptChangeScanInfo) {
        return PersonScheduledMapper.selectDeptChangeScanInfoList(deptChangeScanInfo);
    }

    @Override
    public List<SalaryChangeScanInfo> selectSalaryChangeScanInfoList(SalaryChangeScanInfo salaryChangeScanInfo) {
        return PersonScheduledMapper.selectSalaryChangeScanInfoList(salaryChangeScanInfo);
    }

    @Override
    public List<EmployeeStatusScanInfo> selectEmployeeStatusScanInfoList(EmployeeStatusScanInfo employeeStatusScanInfo) {
        return PersonScheduledMapper.selectEmployeeStatusScanInfoList(employeeStatusScanInfo);
    }

    @Override
    public Map<String, Object> getPositionByUserId(Long userId) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            map.put("nickName", sysCommonService.getUserName(userId));
            map.put("oldPositionId", sysCommonService.selectPositionByUserId(userId));
            map.put("oldPositionLevelId", sysCommonService.selectPositionLevelByUserId(userId));
            map.put("oldPositionLevelIdOption", sysCommonService.getPositionLevelOption(sysCommonService.selectPositionByUserId(userId).getPositionId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> getPostByUserId(Long userId) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            map.put("nickName", sysCommonService.getUserName(userId));
            map.put("oldPostId", sysCommonService.selectPostByUserId(userId));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map<String, Object> getDeptInfoByUserId(Long userId) {
        HashMap<String, Object> map = new HashMap<>();
        SysUser user = sysCommonService.getSysUserByUserId(userId);
        if (StringUtils.isNotNull(user)) {
            map.put("oldDeptId", user.getDeptId());
            map.put("nickName", user.getNickName());
            map.put("oldDeptName", sysCommonService.getDeptName(user.getDeptId()));
        }
        return map;
    }

    @Override
    public Map<String, Object> obtainEmployeeStatusInformation(Long userId) {
        HashMap<String, Object> map = new HashMap<>();
        SysUser user = sysCommonService.getSysUserByUserId(userId);
        if (StringUtils.isNotNull(user)) {
            map.put("nickName", user.getNickName());
            map.put("employeeStatus", user.getEmployeeStatus());
        }
        return map;
    }

    @Override
    public Map<String, Object> obtainSalaryInformation(Long userId) {
        HashMap<String, Object> map = new HashMap<>();
        SysUser user = sysCommonService.getSysUserByUserId(userId);
        if (StringUtils.isNotNull(user)) {
            map.put("nickName", user.getNickName());
            map.put("salaryLevel", user.getSalaryScale());
        }
        return map;
    }
}
